package com.rongji.dfish.hello.index.service;

import java.util.ArrayList;
import java.util.List;

import org.springframework.stereotype.Service;

import com.rongji.dfish.base.Page;
import com.rongji.dfish.base.Utils;
import com.rongji.dfish.framework.FilterParam;
import com.rongji.dfish.hello.entity.PubUser;
import com.rongji.dfish.hello.pub.service.CommonService;

@Service
public class UserService extends CommonService<PubUser> {

	public List<PubUser> findUsers(Page page, FilterParam fp) {

		StringBuilder hql = new StringBuilder();
		hql.append("FROM PubUser t");
		String qUserName = fp.getValueAsString("qUserName");
		List<Object> params = new ArrayList<Object>();
		if (Utils.notEmpty(qUserName)) {
			hql.append(" AND t.userName LIKE ?");
			params.add("%" + qUserName + "%");
		}
		String qLoginName = fp.getValueAsString("qLoginName");
		if (Utils.notEmpty(qLoginName)) {
			hql.append(" AND t.loginName=?");
			params.add(qLoginName);
		}
		String qMobilePhone = fp.getValueAsString("qMobilePhone");
		if (Utils.notEmpty(qMobilePhone)) {
			hql.append(" AND t.mobilePhone=?");
			params.add(qMobilePhone);
		}

		List<PubUser> userList = (List<PubUser>) pubCommonDAO.getQueryList(hql.toString().replaceFirst("AND", "WHERE"),
				page, params.toArray());
		return userList;
	}

}
